<template>
	<view>
		<image src="../../static/login/top.png" mode="widthFix" class="top"></image>
		<image src="../../static/login/logo.jpg" mode="widthFix" class="logo"></image>
		<view class="desc">
			<text class="name">有我在您可放心畅饮</text>
		</view>
		<button class="btn" @tap="wxLogin()">乘客登陆</button>
		<view class="register-container">
			没有账号?
			<text class="link" @tap="toRegisterPage()">立即注册</text>
		</view>
		<text class="remark">小程序仅限于飞驰专车代驾使用,登录前请先进行微信注册,注册前请消息阅读注册需求和使用流程</text>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			code: null
		};
	},
	methods: {
		toRegisterPage(){
			
			uni.navigateTo({
				url:"/pages/register/register"
			})
		},
		wxLogin(){
			let _this = this;
			uni.showLoading({ title:"登录中..." });
			wx.login({
					success(res) {
						// 封装传递参数
						const param = {
							//拿到微信授权码
							code: res.code,
							// 传递乘客类型
							type: _this.Consts.LOGIN_TYPE.TYPE_CUSTOMER,
			
						}
						_this.post(_this.Consts.API.LOGIN_WECHAT, param, (res) => {
							let {
								success,
								message,
								data
							} = res.data;
							if (success) {
								// 存储登录会话 到本地
								uni.setStorageSync("satoken", data.satoken),
									uni.setStorageSync("login", data.login),
									uni.showToast({
										title: "登录成功",
										icon: "success"
									}),
									setTimeout(()=>{
										uni.switchTab({
											url: "/pages/workbench/workbench"
										})
									},1500)
								
							} else {
								uni.showToast({
									title: "登录失败",
									icon: "error"
								})
							}
						})
			
					}
				})
			},
	},
	onLoad: function() {}
};
</script>

<style lang="less">
@import url('login.less');
</style>
